package com.fucking.great.context.engine;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.StrUtil;
import groovy.lang.Script;
/**
 * @deprecated  这个他会带锁影响性能.
 * java调用groovy工具类（engine方法为执行指定文件）
 * @see GroovyClassLoaderEngine
 * @date 2020-09-14
 */
@Deprecated
public class GroovyCacheEngine extends GroovyEngine{
    // 默认30分钟缓存.
    private static final TimedCache<String, Script> SCRIPT_CACHE = CacheUtil.newTimedCache( 30 * 60  * 1000);
    //
    @Override
    public Script getScriptInstance(String cacheKey, String scriptStr) {
        if (StrUtil.isBlank(cacheKey)) {
            cacheKey = scriptStr;
        }
        //
        String finalCacheKey = cacheKey;
        return   SCRIPT_CACHE.get(cacheKey, () -> {
            return super.getScriptInstance(finalCacheKey,scriptStr);
        });
    }
}
